package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.mybatis.Pagination;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.user.SopUserBO;
import com.ymk.core.code.cmd.UserCmdCode;
import com.ymk.service.ISopUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class SopUserListCmd extends ACmd {

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        SopUserBO reqData = super.getData(sign, SopUserBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("status",reqData.getStatus())
                .addParam("name",reqData.getName())
                .addParam("mobile",reqData.getMobile())
                .addParam("loadRole",true)
                .setReturnStruct(sign.getReturnStruct());

        Pagination pagination = sign.buildPage();
        pagination.setParams(paramsBuilder.build());

        List<SopUserBO> respDataList = this.SopUserService.listForPage(pagination);

        respSign.setPageInfo(pagination);
        respSign.setSource(super.getSource(respDataList));

        return respSign;
    }

    @Override
    public String getCmdCode() {
        return UserCmdCode.SOP_USER_LIST;
    }

    @Autowired
    private ISopUserService SopUserService;
}